﻿@using PagedList
@model PagedList.IPagedList<ShenLanCMS.Models.User>
@{
    ViewBag.Title = "管理员管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<fieldset>
    <legend>管理员管理 | @Html.ActionLink("添加", "add")</legend>
    <br />
    <table>
        <tr>
            <th>
                用户名
            </th>
            <th>
                邮箱
            </th>
 
            <th>
                注册时间
            </th>
            <th>
                上次活动时间
            </th>
            <th>
                操作
            </th>
        </tr>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.UserName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Email)
                </td>
 
                <td>
                    @Html.DisplayFor(modelItem => item.RegTime)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.LastActivityTime)
                </td>
                <td>
                    @Html.ActionLink("详细", "Details", new { id = item.UserID }) | <a href="javascript:delUser('@item.UserID')">
                        删除</a> | <a href="javascript:delAdmin('@item.UserID')">删除管理员身份</a>
                </td>
            </tr>
        }
    </table>
    <div style="width: auto; height: 30px; margin-top: 10px; text-align: center;">
        @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
        / @Model.PageCount
        &nbsp;
        @if (Model.HasPreviousPage)
        {
            @Html.ActionLink("首页", ViewData["actionName"].ToString(), new { page = 1, currentFilter = ViewBag.CurrentFilter })
            @Html.Raw("&nbsp;");
            @Html.ActionLink(" 上一页", ViewData["actionName"].ToString(), new { page = Model.PageNumber - 1, currentFilter = ViewBag.CurrentFilter })
        }
        else
        {
            @Html.Raw("首页&nbsp;&nbsp;上一页")
        }
        &nbsp;
        @if (Model.HasNextPage)
        {
            @Html.ActionLink("下一页 ", ViewData["actionName"].ToString(), new { page = Model.PageNumber + 1, currentFilter = ViewBag.CurrentFilter })
            @Html.Raw("&nbsp;");
            @Html.ActionLink(" 尾页", ViewData["actionName"].ToString(), new { page = Model.PageCount, currentFilter = ViewBag.CurrentFilter })
        }
        else
        {
            @Html.Raw("下一页&nbsp;&nbsp;尾页")
        }
    </div>
</fieldset>
<script type="text/javascript">
    function delUser(obj) {
        if (confirm("确定要删除该管理员吗?")) {
            $.post("/user/deladminuser/" + obj, function (data) {
                alert(data);
                if (data == "删除成功")
                    window.location.reload();
            });
        }
    }
    function delAdmin(obj) {
        if (confirm("确定要删除该管理员身份吗?")) {
            $.post("/user/setadmin?mod=deladmin&id=" + obj, function (data) {
                alert(data);
                if (data == "操作成功")
                    window.location.reload();
            });
        }
    }
</script>
